package com.navi.loaddata.loadService.impl.Dcdata.cf;

import com.navi.loaddata.core.etlException.ETLException;
import com.navi.loaddata.core.mesEntity.SpcDcdata;
import com.navi.loaddata.core.oracleEntity.cf.EtlCfPdsGlassV;
import com.navi.loaddata.core.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author jay
 */
@Service
public class ProcessDcDataServiceCF2 {

    private static final Logger logger = LoggerFactory.getLogger(ProcessDcDataServiceCF2.class);
//    public List<EtlCfPdsGlassV> processDcData(List<SpcDcdata> spcDcdataEntityList,int errorProcessSpcDcdata) throws ETLException {
//        List<EtlCfPdsGlassV> etlCfPdsGlassVList = new ArrayList<>();
//        for(int i=0;i<spcDcdataEntityList.size();i++){
//            EtlCfPdsGlassV etlCfPdsGlassV = new EtlCfPdsGlassV();
//            try {
//                etlCfPdsGlassV = processDcData(spcDcdataEntityList.get(i), errorProcessSpcDcdata);
//                etlCfPdsGlassVList.add(etlCfPdsGlassV);
//            }catch (Exception e){
//                logger.error(LoggerUtil.stackTraceToString(e));
//                throw new ETLException(e.getMessage());
//            }
//        }
//        return etlCfPdsGlassVList;
//    }

    public EtlCfPdsGlassV processDcData(SpcDcdata d, int errorProcessSpcDcdata) throws ETLException {
        EtlCfPdsGlassV etlCfPdsGlassV = new EtlCfPdsGlassV();
        try {
            etlCfPdsGlassV.setStepId(d.getProcessoperationname());
            etlCfPdsGlassV.setSubEquipId(d.getUnitname());
            etlCfPdsGlassV.setGlassId(d.getMaterialname());
            etlCfPdsGlassV.setGlassEndTime(d.getEventtime());
            etlCfPdsGlassV.setProductId(d.getProductspecname());
            etlCfPdsGlassV.setRouteId(d.getProcessflowname());
            etlCfPdsGlassV.setGroupId(d.getLotname());
//            etlCfPdsGlassV.setLotId(d.getLotname());
            etlCfPdsGlassV.setEquipId(d.getMachinename());
            etlCfPdsGlassV.setRunMode(d.getRunmode());
            etlCfPdsGlassV.setRecipeId(d.getProductspecname());
            etlCfPdsGlassV.setOperatorId(d.getEventuser());
            etlCfPdsGlassV.setOwnerId(d.getOwnercode());
            etlCfPdsGlassV.setMesLinkKry(d.getMeslinkkey());
        }catch (Exception e){
            logger.error(errorProcessSpcDcdata+":"+e.getMessage());
            logger.error(LoggerUtil.stackTraceToString(e));
            throw new ETLException(errorProcessSpcDcdata+":"+e.getMessage());
        }
//        etlCfPdsGlassV.setTaShift(); todo
        return etlCfPdsGlassV;
    }

}
